<template>
  <div id="login">
    <video src="../assets/video/wanglujia.mp4" class="video_gb" autoplay muted loop></video>
    <div class="bg_mask"></div>
    <h2>用户登录</h2>
    <el-form ref="form" class="login_box" size="normal">
      <el-form-item prop="username">
        <el-input prefix-icon="el-icon-user-solid" v-model="username" placeholder="请输入账号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input prefix-icon="el-icon-lock" v-model="password" show-password placeholder="请输入密码"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button  type="success" @click="login">登 录</el-button>
        <el-button type="primary" @click="$router.push('/register')">没有账号?前往注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {userLogin} from "../network/loginRequest";

export default {
  name: "Login",
  data(){
    return{
      username:"",
      password:"",
    }
  },
  methods:{
    login(){
      userLogin(this.username,this.password).then((result)=>{
        console.log(result);
        if (result.data.code===200){
          //存储用户的信息
          sessionStorage.setItem("wlj-user-id",result.data.data.id);
          sessionStorage.setItem("wlj-user-image",result.data.data.avatar);
          sessionStorage.setItem("wlj-user-username",result.data.data.username);
          sessionStorage.setItem("wlj-user-password",this.password);
          this.$message({
            message: '登录成功!',
            type: 'success'
          });
          this.$router.push("/home");
        }else{
          this.$message.error(result.data.message);
        }
      }).catch((reason)=>{
        console.log(reason);
      })
    }
  }
}
</script>

<style scoped>
#login{
  position: relative;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
#login h2{
  text-align: center;
  font-size: 25px;
  color: #ffffff;
}
.login_box{
  position: absolute;
  width: 400px;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-70%);
}
.video_gb{
  position: absolute;
  top: 0;
  left: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: blur(2px);
}
.bg_mask{
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.5);
}
</style>
